{extend name="common:base" /}
{block name="page_current"}
<div class="fui-page-group statusbar">
    <div class='fui-page fui-page-current shop-index-page'>
    <div class='fui-content navbar'>
        <div class='fui-swipe' >
            <div class='fui-swipe-wrapper'>
                <div class='fui-swipe-item' ><img src="http://hejiangshop.me/attachment/images/1/2018/06/jB6i97vte7l6svMPlcB6m96BbL3kYl.jpg" /></div>
                <div class='fui-swipe-item' ><img src="http://hejiangshop.me/attachment/images/1/2018/06/L2mX222dD23yNXP00xM2322Xw3Lwbg.jpg" /></div>
                <div class='fui-swipe-item' ><img src="http://hejiangshop.me/attachment/images/1/2018/06/u0tiEcl6PC94RiFF8td0447fR7ermM.jpg" /></div>
            </div>
            <div class='fui-swipe-page'></div>
        </div>
        <form action="./index.php?i=1&c=entry&m=ewei_shopv2&do=mobile&r=goods" method="post">
            <div class="fui-searchbar bar">
                <div class="searchbar center">
                    <input type="submit" class="searchbar-cancel searchbtn" value="搜索" />
                    <div class="search-input">
                        <i class="icon icon-search"></i>
                        <input type="search" placeholder="输入关键字..." class="search" name="keywords">
                    </div>
                </div>
            </div>
        </form>
        <script>
            $(function () {
                $("input[name='keywords']").focusin(function () {
                    $(this).removeAttr('placeholder');
                });
                $("input[name='keywords']").focusout(function () {
                    $(this).attr('placeholder','输入关键字...');
                });
                $("form").submit(function () {
                    $(this).find("input[name='keywords']").blur();
                });
            });
        </script>
        <div id="recommand">
        </div>
        <div class='infinite-loading' style="text-align: center; color: #666;">
            <span class='fui-preloader'></span>
            <span class='text'> 正在加载...</span>
        </div>
        <script type="text/html" id="tpl_recommand">
            <!--
            <div class="fui-line" style="background: #f4f4f4;">
                <div class="text text-danger"><i class="icon icon-hotfill"></i> 店铺推荐</div>
            </div>
            -->
            <div class="fui-goods-group block border">
                {{#  layui.each(d.list, function(index, item){ }}
                <div class="fui-goods-item" data-goodsid="{{ item.id }}" data-type="{{ item.type }}">
                    <a href="javascript:goGoodsDetail({{ item.id }});">
                        <div class="image" data-lazy-background="{{ item.thumb }}">
                            {{#  if(item.total<=0){ }}
                            <div class="salez" style="background-image: url('__STATIC__/m/imgs/shouqin.png'); "></div>
                            {{#  } }}
                        </div>
                    </a>
                    <div class="detail">
                        <a href="javascript:goGoodsDetail({{ item.id }});">
                            <div class="name">
                                {{ item.goods_name }}
                            </div>
                        </a>
                        <div class="price" style="margin-top: 0.3rem">
                            <span class="text">￥{{ item.minprice }}</span>
                            <span class="buy" data-type="{{ item.type }}">购买</span>
                        </div>
                    </div>
                </div>
                {{#  }); }}
            </div>
        </script>
    </div>
    {include file="common/footer_bar_nav" /}
        <script>
            $(function () {
                getRecommand();
            })
            function getRecommand() {
                core.json("{:url('m/Index/get_recommand')}",{keyword:$('#search').val()},function (json) {
                    console.log(json);
                    if(json.code){
                        if(!json.data.has_more){
                            // 没有更多数据的时候，隐藏 正在加载
                            hideLoading();
                        }
                        var view = document.getElementById('recommand');
                        if(json.data.list.length > 0){
                            var getTpl = $('#tpl_recommand').text();
                            layui.laytpl(getTpl).render({list:json.data.list}, function(html){
                                view.innerHTML = html;
                                setTimeout(function () {
                                    $('.fui-content').lazyload();
                                })
                            });
                        }
                        else{
                            view.innerHTML = '';
                            $('#noaddress').show(0);
                        }
                    }
                },false,false);
            }
            function hideLoading() {
                $('.infinite-loading').hide(0);
            }
            function goGoodsDetail(_id) {
                var baseGoodsDetailUrl = "{:url('m/Goods/detail')}";
                $.router.load(baseGoodsDetailUrl + '?id=' + _id);
            }
        </script>
</div>
</div>
{/block}
